'use strict';
module.exports = {
	/**
	 * XXXnameXXX
	 * @url admin/pages/kh/yhsj/czjl/xnzf/refundSuc 前端调用的url参数地址
	 * data 请求参数
	 * @param {String} params1  参数1
	 */
	main: async (event) => {
		let {
			data = {}, userInfo, util, filterResponse, originalParam
		} = event;
		let {
			customUtil,
			uniID,
			config,
			pubFun,
			vk,
			db,
			_
		} = util;
		let {
			uid,
			order_fee,
			pay_order_id,
		} = data;
		let res = {
			code: 0,
			msg: ""
		};
		// 业务逻辑开始-----------------------------------------------------------


		if (userInfo.username != "admin") {
			res = {
				code: 0,
				msg: '操作失败！非admin账户不能操作退款'
			};
			return res;
		}

		//修改订单状态为已退款。0：未支付  1：已支付  2：已退款
		let edit_pay_status = await db.collection('a_recharge').where({
			out_trade_no: pay_order_id
		}).update({
			pay_status: 2,
			remark: "已退款。退款金额(单位：分)：" + order_fee || "全额"
		})

		// 执行add命令，添加退款操作日志
		let dbName = "a_log"; // 表名
		res.id = await vk.baseDao.add({
			dbName,
			dataJson: {
				user_id: userInfo._id,
				username: userInfo.username,
				ip: originalParam.context.CLIENTIP,
				osName: originalParam.context.osName,
				osVersion: originalParam.context.osVersion,
				deviceId: originalParam.context.deviceId,
				ua: originalParam.context.ua,
				remark: "后台操作退款记录",
				_add_time: new Date().getTime(),
				_add_time_str: vk.pubfn.timeFormat(new Date(), "yyyy-MM-dd hh:mm:ss")
			}
		});

		res = {
			code: 0,
			msg: '退款成功'
		};




		// 业务逻辑结束-----------------------------------------------------------
		return res;
	}
}